package MySQL;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class Mysql {
    protected Connection connection;

    public Connection getConnection() {
        return connection;
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void connect() throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/school?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("0714");
        connection = dataSource.getConnection();
    }
    public void getInterface(){
        System.out.println("**************************************");
        System.out.println("**************************************");
        System.out.println("******         1.class          ******");
        System.out.println("******         2.counsellor     ******");
        System.out.println("******         3.course         ******");
        System.out.println("******         4.course_center  ******");
        System.out.println("******         5.student        ******");
        System.out.println("******         6.teacher        ******");
        System.out.println("******         0.exit           ******");
        System.out.println("**************************************");
        System.out.println("**************************************");
        System.out.println("请输入你要获取的表的信息:");
    }
    public void mysql() throws SQLException {
        connect();
        new Select(connection).select();
        connection.close();
    }
}
